#include "globalData.h"
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

/* the map for blocked squares */
BitBoard BLOCKED_MAP;

/* masks used during move generation */
BitBoard DIRECTION_MASK[MAX_DIRECTION];

/* the color agent is playing */
BoardState AGENT_PLAYER;

/* masks used for disc features */
BitBoard DISC_FEATURE[15];

/* masks used to get the lower n bits and higher n bits of numbers */
U64 BitMaskLow[50], BitMaskHigh[50];

/* initialise the bit masks etc */
void initialiseMasks()
{
    // Low/High-est bit masks, used for bit shifting
    U64 masklow = 1;
    for (int i = 1; i < 50; i++)
    {
        BitMaskLow[i] = masklow;
        BitMaskHigh[50-i] = FIFTY_MASK - masklow;
        masklow |= (masklow << 1);
    }
    
    // Direction masks, used for bit shifting
    for (int i = 0; i < MAX_DIRECTION; i++)
    {
        DIRECTION_MASK[i].top = 0xFFFFFFFFFFFFFFFF;
        DIRECTION_MASK[i].bottom = 0xFFFFFFFFFFFFFFFF;
        
        switch (i)
        {
        case LEFT:
        case DOWN_LEFT:
        case UP_LEFT:
            DIRECTION_MASK[i].top ^= RIGHT_BARRIER;
            DIRECTION_MASK[i].bottom ^= RIGHT_BARRIER;
            break;
        case RIGHT:
        case DOWN_RIGHT:
        case UP_RIGHT:
            DIRECTION_MASK[i].top ^= LEFT_BARRIER;
            DIRECTION_MASK[i].bottom ^= LEFT_BARRIER;
        }
    }
    
    
    // disc feature masks, used as part of static evaluation
    BoardState disk_types[15][10][10];
    
    memset(disk_types, 0, sizeof(BoardState)*1500);
    
    disk_types[0][0][0] = WHITE;
    disk_types[1][0][1] = WHITE;
    disk_types[2][0][2] = WHITE;
    disk_types[3][0][3] = WHITE;
    disk_types[4][0][4] = WHITE;
    disk_types[5][1][1] = WHITE;
    disk_types[6][1][2] = WHITE;
    disk_types[7][1][3] = WHITE;
    disk_types[8][1][4] = WHITE;
    disk_types[9][2][2] = WHITE;
    disk_types[10][2][3] = WHITE;
    disk_types[11][2][4] = WHITE;
    disk_types[12][3][3] = WHITE;
    disk_types[13][3][4] = WHITE;
    disk_types[14][4][4] = WHITE;
    
    for (int i = 0; i < 15; i++)
    {
        for (int x = 0; x < 10; x++)
        {
            for (int y = 0; y < 10; y++)
            {                
                if (disk_types[i][x][y] == WHITE)
                {
                    // reflection by x-axis
                    disk_types[i][9-x][y] = WHITE;
                    // reflection by y-axis
                    disk_types[i][x][9-y] = WHITE;
                    // reflection by both axis
                    disk_types[i][9-x][9-y] = WHITE;
                    
                    // transpose and do the same
                    int tx = y;
                    int ty = x;
                    disk_types[i][tx][ty] = WHITE;
                    disk_types[i][9-tx][ty] = WHITE;
                    disk_types[i][tx][9-ty] = WHITE;
                    disk_types[i][9-tx][9-ty] = WHITE;
                }
            }
        }
        DISC_FEATURE[i] = ArrayToBitBoard(disk_types[i], WHITE);
    }
}
